<template>
  <!-- 业务审批 -->
    <CommonTitle titleName="上报请示决策会议名"></CommonTitle>
    <div class="box">
        <el-form
                :inline="true"
                label-width="160"
                :model="formInline"
                :rules="rules"
                ref="formRef"
                class="demo-form-inline"
        >
            <el-row>
                <el-col :span="8"
                ><el-form-item label="关联项目集">
                    <el-input
                            v-model="formInline.projectSetName"
                            disabled
                            placeholder=""
                    />
                </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="项目名称">
                        <el-input
                                v-model="formInline.projectName"
                                disabled
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="项目编号">
                        <el-input v-model="formInline.projectId" disabled placeholder="" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="项目分类">
                        <el-input
                                v-model="formInline.typeName"
                                disabled
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="业务单元">
                        <el-input
                                v-model="formInline.businessUnitName"
                                disabled
                                placeholder=""
                        />

                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="计划实施时间范围">
                        <el-date-picker
                                v-model="formInline.predictStartTime"
                                type="daterange"
                                disabled
                                range-separator="-"
                                start-placeholder="开始时间"
                                end-placeholder="结束时间"
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="项目位置">
                        <el-input disabled v-model="formInline.streetName" />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="项目详细地址">
                        <el-input disabled v-model="formInline.address" />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="拟计划总投额">
                        <el-input disabled v-model="formInline.projectAmount" />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="项目类型">
                        <el-select
                                v-model="formInline.projectCategory"
                                clearable
                                disabled
                                placeholder="项目类型"
                                @change="streerTypeChange"
                        >
                            <el-option value="1" label="公司自建"></el-option>
                            <el-option value="2" label="政府投资"></el-option>
                            <el-option value="3" label="代建项目"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="项目立项部门">
                        <el-input disabled v-model="formInline.departmentName" />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="项目负责人">
                        <el-input disabled v-model="formInline.userName" />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="项目编码">
                        <el-input disabled v-model="formInline.projectId" />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="工作细项名称">
                        <el-input disabled v-model="formInline.itemName" />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="会议名称" prop="decisionName">
                        <el-input
                                :disabled="state.disabled"
                                v-model="formInline.decisionName"
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="申请原因" prop="decisionReason">
                        <el-input
                                :disabled="state.disabled"
                                type="textarea"
                                v-model="formInline.decisionReason"
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>

                <p v-if="state.disabled">审批结果</p>
                <el-col :span="24" v-if="state.disabled">
                    <el-form-item label="审批单编号">
                        <el-input
                                disabled
                                v-model="formInline.flowId"
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="state.disabled">
                    <el-form-item label="审批状态">
                        <el-select disabled
                                   v-model="formInline.examineStatus"
                                   placeholder="">
                            <el-option value="1" label="审核中">
                            </el-option>
                            <el-option value="2" label="审核通过">
                            </el-option>
                            <el-option value="3" label="审核驳回">
                            </el-option>

                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="state.disabled">
                    <el-form-item label="查看审批流程">
                        <el-button type="primary" @click="openHandler(formInline.routeUrl)" class="button_edit">查看审批流程</el-button>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="isLook === '0' || isLook === '2'" >
                    <el-button @click="submit" type="primary" class="button_view">确认上报</el-button>
                    <el-button type="primary" @click="goback" class="button_cancel2"> 取消 </el-button>
                  </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script setup>
import { businessApi, projectConfigApi, department } from '@/api/project'

import { ref, reactive, onBeforeMount, onMounted } from 'vue'
import {
    ElDialog,
    ElForm,
    ElDatePicker,
    ElFormItem,
    ElRow,
    ElCol,
    ElMessage,
    ElSwitch
} from 'element-plus'
import CommonTitle from '@/components/CommonTitle.vue'
import FileUpload from '@/components/FileUpload.vue'
import { useRouter, useRoute } from 'vue-router'
import { getURLhandler } from '@/views/constructionProjectManage/static/utools.js'
import {taskApi} from "@/api/investment";

let router = useRouter()
let route = useRoute()

const getProjectId = router.currentRoute.value.params.projectId;
const getProjectTaskId = router.currentRoute.value.params.projectTaskId;
const getItemId = router.currentRoute.value.params.itemId;
const isLook = router.currentRoute.value.params.isLook;

const formInline = reactive({
    files: [],

    decisionName: '',
    decisionReason: ''
})
const state = reactive({
    projectTaskId: '',
    departmentOptions: [],
    disabled: false,
    projectId: '',
    user: '',
    list: [
        {
            value: '1',
            label: '综合管理部'
        },
        {
            value: '2',
            label: '财务金融部'
        },
        {
            value: '3',
            label: '纪检监察部'
        },
        {
            value: '4',
            label: '开发建设部'
        },
        {
            value: '5',
            label: '投资发展部'
        },
        {
            value: '6',
            label: '招标合约部'
        },
        {
            value: '7',
            label: '数字科技部'
        },
        {
            value: '8',
            label: '设计部'
        },
        {
            value: '9',
            label: '文体事业部'
        },
        {
            value: '10',
            label: '养老事业部'
        },
        {
            value: '11',
            label: '邻里中心事业部'
        },
        {
            value: '12',
            label: '社区商业事业部'
        },
        {
            value: '13',
            label: '社区商业事业二部'
        },
        {
            value: '14',
            label: '文创传媒公司'
        },
        {
            value: '15',
            label: '体育公司'
        },
        {
            value: '16',
            label: '佳医医学检验实验室'
        },
        {
            value: '17',
            label: '领创公司'
        },
        {
            value: '18',
            label: '托育公司'
        },
        {
            value: '19',
            label: '医疗公司'
        },
        {
            value: '20',
            label: '领川置业公司'
        }
    ]
})
const rules = {
    decisionReason: [
        { required: true, message: '申请原因不能为空', trigger: 'blur' }
    ],
    decisionName: [
        { required: true, message: '会议名称不能为空', trigger: 'blur' }
    ]
}

const goback = () => {
    router.go(-1)
}
const openHandler=(url)=>{
    window.open(url)
}
const formRef = ref(null)
const submit = () => {
    formRef.value.validate(async (valid, fields) => {
        if (valid) {
            let obj={}
            obj.decisionName = formInline.decisionName;
            obj.decisionReason = formInline.applyReason;
            obj.taskId = getProjectTaskId;
            obj.itemId =getItemId;
            obj.projectId = getProjectId;

            await taskApi.addDecisionMakingMeetings(obj).then((res) => {
                if (res.code == '200') {
                    ElMessage.success('操作成功')
                    router.go(-1)
                }
            })
        }
    })
}

onMounted(() => {
    taskApi
        .getDecisionMakingMeetings({
            taskId: getProjectTaskId,
            itemId: getItemId,
            projectId: getProjectId
        })
        .then((res) => {
            if (res.code == '200') {
                for (const key in res.data) {
                    if (Object.hasOwnProperty.call(res.data, key)) {
                        if (key == 'predictStartTime') {
                            formInline[key] = [res.data[key], res.data['predictEndTime']]
                            continue
                        }
                        if (key == 'files') {
                            formInline[key] = res.data[key] || []
                            continue
                        }
                        formInline[key] = res.data[key]
                    }
                }
            }
        })
})
</script>

<style lang="scss" scoped>
.el-form-item,
.el-select {
  width: 100%;
}
.box {
  border-radius: 10px;
  border: 1px solid #e3e7f1;
  padding: 34px 90px;
}
</style>
